package com.cloud.pole.user.biz;

import java.util.List;
import java.util.Map;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ace.cache.annotation.Cache;
import com.ace.cache.annotation.CacheClear;
import com.cloud.pole.common.biz.BaseBiz;
import com.cloud.pole.common.constant.UserConstant;
import com.cloud.pole.mapper.BaseUserMapper;
import com.cloud.pole.user.model.entity.BaseUser;
import com.cloud.pole.user.model.entity.CpChannelNet;

/**
 * ${DESCRIPTION}
 *
 * @author wanghaobin
 * @create 2017-06-08 16:23
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class BaseUserBiz extends BaseBiz<BaseUserMapper, BaseUser> {
	
    public void insertUseGeneratedKeys(BaseUser entity) {
        String password = new BCryptPasswordEncoder(UserConstant.PW_ENCORDER_SALT).encode(entity.getPassWord());
        entity.setPassWord(password);
        mapper.insertUseGeneratedKeys(entity);
    }

    @Override
    @CacheClear(pre="user{1.userName}")
    public void updateSelectiveById(BaseUser entity) {
        super.updateSelectiveById(entity);
    }

    /**
     * 根据用户名获取用户信息
     * @param username
     * @return
     */
    @Cache(key="user{1}")
    public BaseUser getUserByUserName(String userName){
    	BaseUser user = new BaseUser();
        user.setUserName(userName);
        return mapper.selectOne(user);
    }
    
    public List<BaseUser> selectPageShopGoodsAdminList(Map<String, Object> map) {
		return mapper.selectPageShopGoodsAdminList(map);
	}
    
    public BaseUser selectByBaseUserId(Integer userId) {
    	return mapper.selectByBaseUserIdKey(userId);
    }
    
    public BaseUser selectByMarketCodeAp(String marketCode) {
    	return mapper.selectMarketCode(marketCode);
    }
    

    public void updateByToBaseUser(BaseUser baseUser) {
    	mapper.updateToBaseUserUp(baseUser);
    }
}
